// pages/apply/apply.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classroom:'',
    array: ['活动', '调课'],
    date: '',
    time: '',
    time1: '',
    name:'',
    number:'',
    activetype:'',
    reason:'',
    objectArray: [
      {
        id: 0,
        name: '活动'
      },
      {
        id: 1,
        name: '调课'
      },
    ],
    index: 0,
    
  },
  bindPickerChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },


  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  bindTimeChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time: e.detail.value
    })
  },
  bindTimeChange1: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      time1: e.detail.value
    })
  },
  contentSaveTime:0,
  getName: function(t){
    // console.log(t.detail.value)
    
    this.setData({
      name:t.detail.value
    })
    // console.log(this.data.name)
    let tm = Date.now();
    if((this.contentSaveTime + 500) > tm){      // > tm表示还没有超时，不用保存，直接return
      return;
    }
    this.contentSaveTime = tm;
  },
  getactivetype:function(t){
    this.setData({
      activetype:t.detail.value
    })
  },
  getReason: function(t){
    this.setData({
      reason:t.detail.value
    })
    let tm = Date.now();
    if((this.contentSaveTime + 500) > tm){      // > tm表示还没有超时，不用保存，直接return
      return;
    }
    this.contentSaveTime = tm;
  },
  toConfirm: function(){
    if(this.data.time==this.data.time1){
      wx.showModal({
        title: '提示',
        content: '填写一个正确的时间段',
        // showCancel: false,
        success: function(res) {
          if (res.confirm) {
           console.log('用户点击确认')
          }else{
            console.log('用户点击取消')
          }
        }
      })
      console.log("请选择一个时间段")
    }
    else if(this.data.date==''){
      wx.showModal({
        title: '提示',
        content: '请填写日期',
        // showCancel: false,
        success: function(res) {
          if (res.confirm) {
           console.log('用户点击确认')
          }else{
            console.log('用户点击取消')
          }
        }
      })
      console.log("日期不可以为空")
    }
    else if(this.data.reason==''){
      wx.showModal({
        title: '提示',
        content: '请填写申请原因',
        // showCancel: false,
        success: function(res) {
          if (res.confirm) {
           console.log('用户点击确认')
          }else{
            console.log('用户点击取消')
          }
        }
      })
      console.log('请填写申请原因')
    }
    else{
      wx.navigateTo({
        url: '../confirm/confirm?name='+this.data.name+'&number='+this.data.number+'&date='+this.data.date+'&time='+this.data.time+'&time1='+this.data.time1+'&type='+this.data.array[this.data.index]+'&classroom='+this.data.classroom+'&reason='+this.data.reason+'&activetype='+this.data.activetype,
      })
    }
    // console.log(this.data.name)
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    this.setData({
      classroom:options.room,
      time:options.time1,
      time1:options.time2,
      date:options.date
    }) 
    let num=wx.getStorageSync('username')
    let na=wx.getStorageSync('name')
    console.log(num)
    this.setData({
      number:num,
      name:na
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})